package ss;

/**
 * Created by Administrator on 2016/4/13.
 */
public class Complex {

    private int sh,xu;

    Complex(){

        this.sh=0;

        this.xu=0;

    }

    Complex(int sh){

        this.sh=sh;

        this.xu=0;

    }

    Complex(int sh,int xu){

        this.sh=sh;

        this.xu=xu;

    }

    public void addFu(Complex p1,Complex p2){

        System.out.println("这两个复数的和为：");

        this.sh=p1.sh+p2.sh;

        this.xu=p1.xu+p2.xu;

        print();

    }

    public void minusFu(Complex p1,Complex p2){

        System.out.println("这两个复数的差为：");

        this.sh=p1.sh-p2.sh;

        this.xu=p1.xu-p2.xu;

        print();

    }

    public void outputFu(){

        System.out.println("复数的值为：");

        print();

    }

    public void print(){

        if(this.xu>0){

            System.out.println(this.sh+"+"+this.xu+"i");

        }else if(this.xu<0){

            System.out.println(this.sh+""+this.xu+"i");

        }else{

            System.out.println(this.sh);

        }

    }

}